/*
 * Description:dfx管理类
 */
#ifndef SYSLOGRECV_H
#define SYSLOGRECV_H

#include <set>
#include <windows.h>
#include <string>
#include <memory>
#include <mutex>
#include <vector>
#include <io.h>
#include "singleton.h"

namespace SYSLOGRECV {
class SysLogRecv {
public:
    /********************
     * 函数：Init
     * 功能：初始化DfxAgent
     * 参数：NA
     * 返回：0初始化成功，-1失败
     ********************/
    static int Init();
    static void QuickStartInit();

    /********************
     * 函数：Quit
     * 功能：退出DfxAgent
     * 参数：NA
     * 返回：NA
     ********************/
    static void Quit();

    SysLogRecv() = default;
    ~SysLogRecv() = default;

private:
    static std::unique_ptr<std::mutex> dfxMutex;
    static void ExecuteDFXThread();
    static void QuickStartDFXThread();
    static void FetchMinidump();
    static void FetchDFXInfo();
    static int MkdirFolders();
    static int CopyFileVmagentLog();
    static int CheckFileMinidump();
    static int CopyFileMinidump();
    static int CopyFileAgentDump();
    static int CopyFileEvtx();
    static int CopyfileEtl();
    static int CopyVmgtLog();
    static int GetDirFileNum(const std::string &dirPath);
    static void GetFileNames(const std::string &dirName, std::set<std::string> &filesNameSet);
    static bool CompareMtime(const _finddata_t &file1, const _finddata_t &file2);
    static std::vector<std::string> GetNewestFiles(
        const std::string &dirName, int n, const std::string &extension, int maxSize);
    static void DeleteFiles(const std::string &folderPath, const std::string &extension);
    static int CopyFiles(
        const std::string &sourcePath, const std::string &desPath, const std::vector<std::string> &files);
    static bool CheckDfxFolderSize();
    static int CopyFilesCommonDump(const std::string &sourceFolder, const std::string &desFolder);
    static long long GetFolderSize(const std::string &folderPath);  // 单位B
    static int GetFileNumInData(const std::string &path);
    static int RemoveOldFile(const std::string &folderPath);
    static bool IsFileGreater(const std::string &filePath, int setFileSize);

    static bool stopReceiveSysLog;
    static const uint32_t TIME_UNIT_MILLI_PER_SECOND = 1000;
    static const uint32_t TIME_UNIT_SECOND_PER_MINUTE = 60;
    static const uint32_t FETCH_LOG_INTERVAL = 5 * TIME_UNIT_SECOND_PER_MINUTE * TIME_UNIT_MILLI_PER_SECOND;
    static const uint32_t RECHECK_DFX_FOLDER_INTERVAL = 5 * TIME_UNIT_MILLI_PER_SECOND;
    static const uint32_t RECHECK_DFX_FOLDER_MAX_TIMES = 5;
    static std::string dfxFolder;
    static std::string systemRoot;
    static std::string localAppData;

    static const uint64_t FILE_SIZE_UNIT_KIB = 1024;
    static const uint64_t FILE_SIZE_UNIT_MIB = 1024 * FILE_SIZE_UNIT_KIB;

    static const uint64_t MAX_FILE_SIZE_ETL_FILE = 200 * FILE_SIZE_UNIT_KIB;
    static const uint64_t MAX_FILE_SIZE_AGENT_DUMP_FILE = 2 * FILE_SIZE_UNIT_MIB;
    static const uint64_t MAX_FILE_SIZE_COMMON_LOG = 5 * FILE_SIZE_UNIT_MIB;
    static const uint64_t MAX_FILE_SIZE_EVTX_FILE = 30 * FILE_SIZE_UNIT_MIB;
    static const uint64_t MAX_FILE_SIZE_DFX_FOLDER = 256 * FILE_SIZE_UNIT_MIB;
    static const uint64_t FILE_RECV_COUNT_ETL = 10;
    static const uint64_t FILE_RECV_COUNT_MINIDUMP = 10;
    static const uint64_t FILE_RECV_COUNT_AGENTDUMP = 5;
};
#define SYSLOGRECV_MANAGER SingletonNew<SYSLOGRECV::SysLogRecv>::GetInstance()
}  // namespace SYSLOGRECV

#endif  // SYSLOGRECV_H